home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Collection of Tools & Utilities
/
Collection of Tools and Utilities.iso
/
batchut
/
strings2.zip
/
STRINGS1.DOC
< prev
Wrap
Text File
|
1992-11-25
|
38KB
|
849 lines
STRINGS.COM (Version 1.0) Copyright (c) 1992
-------------------------------------------------------------------------
First Published in PC Magazine September 10, 1991 (Utilities)
-------------------------------------------------------------------------
This documentation is for STRINGS Version 1.0
STRINGS:
STRINGS enables batch files to manipulate strings, request and
interpret user input, process files, return system information, and
perform simple math by adding functions to the batch file language.
Stores information in either the local or the master environment.
Batch files are quick, simple--and frustratingly limited. They can't
ask you questions or interpret your answers. They can't parse a filename,
tell you how much space is left in your environment, or even perform
simple math. Yet despite their shortcomings, a dozen times a day it's to
batch files that we must turn for routine tasks.
By executing STRINGS.COM from within your batch files, however, you
can make .BAT files do things they could never accomplish on their own.
STRINGS removes many of the restrictions imposed by the limited batch
file vocabulary. For example, you'll be able to perform standard string
manipulations, such as separating a filename from its extension, finding
one string in another, determining the length of a string, and even
reading and writing files.
STRINGS can store its results in environment variables that other
programs (or subsequent calls to STRINGS) can access. It provides simple
functions that allow batch files to ask a user for input, determine
exactly what he entered, and then pass that input to other programs.
STRINGS even includes simple but effective math functions.
USING STRINGS
To execute the program, either from within a batch file or from the
DOS prompt, you enter STRINGS, followed by the desired command function
and its necessary parameters. The full syntax is
STRINGS [/?] [/M] [/Pc] [environment var =] FUNCTION [str1][, str2][, str3]
Thus, for example, to return the left 6 characters of a string, you might
enter
STRINGS LEFT this is a string, 6
To store the This i result you would simply insert the name of the
destination environment variable, followed by an equal sign, before the
command. Thus, to assign the results of this example in the environment
variable VAR1, your command would be
STRINGS VAR1 = LEFT This is a stirng, 6
STRINGS would find or create the environment variable VAR1 in the local
environment and assign the value This i to it.
STRINGS defaults to using the local command-shell environment to
store environment variable results, because that is what batch files use
when substituting strings for environment variables. However, by including
the /M switch before the variable name, you can force STRINGS to use the
system master environment instead of the local command processor
environment. As will be discussed in fuller detail later, you will
use this ability in establishing communications among different DOS
sessions running under Windows.
Another situation in which the /M switch comes in handy is when you
"shell out" to DOS from within a running program. When a program shells
out to DOS, a copy of COMMAND.COM and the accompanying environment are
created. Any environment variable assignments STRINGS makes during this
shelled session will be lost when you exit from DOS back into the original
program, however. If you want to keep any STRINGS assignments made during
a shelled session, use the /M switch.
STRINGS provides two additional command line options. The /? switch
simply displays a help list of the STRINGS function commands. These are
shown in the table below - Figure 1.
The second command line switch is /Pc. Since many strings contain
spaces, by default, STRINGS uses commas instead of spaces to separate
multiple command parameters. If any of the parameter strings themselves
contain commas, however, you can use the /Pc switch to force STRINGS to
employ any unused character as c to differentiate one string from another.
Thus, for example, using /P$ changes the parse character to the dollar
sign ($).
After a parse character is found, STRINGS scans for the first nonspace
character to begin the next parameter. This process has the effect of
ignoring any leading spaces a parameter may have. To force STRINGS to
respect leading spaces, therefore, STRINGS has been written to interpret
consecutive parse characters as the beginning of a parameter.
For example, if a string with leading spaces is to be written to a
file, the line
STRINGS WRITE c:\file.out, ,, This line has 3 leading spaces
should be used. Without the consecutive commas, STRINGS would begin the
next parameter with the letter T. Using the double parse characters,
STRINGS will not append the commas to the line but will keep the proper
number of spaces in the string before the word This.
One additional character requires special handling. DOS uses the
equal sign (=) in assigning a variable name to a value. What happens,
then, if the string parameter you want STRINGS to read into a variable
itself contains an equal sign? You might, for example, want STRINGS to
read the line
DEVICE=HIMEN.SYS
from your CONFIG.BAT file and assign this as VAR2.
STRINGS handles this situation by changing the equal sign character
within the string into the similar-looking but wider ASCII 205 (CDh)
graphics character (=) before assigning the string to an environment
variable. In this example, then, the string actually stored in the
environment would then look like
VAR2=DEVICE=HIMEN.SYS
When it reads an environment variable containing the graphics =
character, STRINGS knows to make the reverse substitution of the normal
equal sign. The only thing you need to be aware of is that a program
other than STRINGS will not know about the need to convert the graphics
equal sign back into a regular equal sign in environment variables stored
by STRINGS.
A final reminder for using STRINGS: DOS limits the length of a program
command line to a maximum of 127 characters. Long strings stored with short
names may run up against this limitation when interpreted.
COMMAND FUNCTIONS
Several of the STRINGS command functions have been used illustratively
above, but a more systematic description of the complete function set is
in order. The functions can be divided into four main groups: (1) string
manipulation; (2) file operations; (3) system functions; and (4) math
functions.
(1) The string manipulation functions start with the LEFT and
RIGHT functions. As shown in the first example, LEFT returns the first n
characters of a string. RIGHT operates similarly: The first parameter
you supply is the string, and the second parameter is the number of
characters you want returned. In both cases, if the string is shorter
than the number you specify, the entire string is returned. If the second
parameter is 0, both functions return a null string.
Assigning a null string to an environment variable removes the
variable from the environment. For example, if the environment contained
the variable PLAY=1234 and the command
STRINGS PLAY = LEFT abcd, 0
was entered, STRINGS would erase the variable PLAY from the environment. Note
that STRINGS makes no attempt to display null strings on the screen.
The MID function is used to return a substring starting at any point
within the original string. As with the LEFT and RIGHT commands, the first
parameter you enter is the string itself. The second parameter is the
numerical position of the starting character. The third parameter is the
requested length of the string you want returned. If the starting character
is higher than the length of the string, a null string is returned.
Not surprisingly, the LENGTH function returns the length of a str